/*
 * copyright (c) 2009 Alexandr [Sn@ble] Surnin
 *
 * This file is part of FrameSeeker.
 *
 * FrameSeeker is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FrameSeeker is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You can read the full version of GNU LGPL in
 * http://www.gnu.org/copyleft/lesser.html
 */


#ifndef FSXMLWRITER_H
#define FSXMLWRITER_H

#include <QObject>
#include <QFile>
#include <QTextStream>
#include <QString>
#include <QList>

#include "FSMotionVector.h"
#include "FSDefines.h"

class FSXMLWriter : public QObject {
    Q_OBJECT
public:

    /** Standart constructor
      \param _fileName XML file name
      */
    FSXMLWriter(const QString &_fileName = "MotionVectors");


    ~FSXMLWriter();

public slots:
    /** Assign XML file's name
      \param _fileName XML file name
      \sa setIndentSize()
      */
    void setFileName(const QString &_fileName);


    /** Set indent size
      \param indSize Indent size
      */
    void setIndentSize(int indSize);


    /** Writing XML standart header
     * \sa writeMotionVector(), writeLine(), writeFooter()
      */
    void writeHeader();


    /** Writing XML standart footer
     * \sa writeMotionVector(), writeLine(), writeHeader()
      */
    void writeFooter();



    /** Writing one motion vector into XML
     * \param mv Motion vector
     * \sa  writeLine(), writeHeader(), writeFooter()
     */
    void writeMotionVector(FSMotionVector &mv);


    /** Write a line to XML-file with automatic indent insertion
     * \param str A string, to be inserted (without "\n")
     * \sa  writeLine(), writeHeader(), writeFooter(), writeMotionVector()
     */
    void writeLine(const QString &str);


    /** Write one line, that starts and ends with similar tag to XML-file
     * A parameter between tags may be any integer
     * \param tag A tag name without "<>"
     * \param value Same integer
     * \sa writeMotionVector(), writeLine(), writeHeader(), writeFooter()
     */
    void writeLine(const char* tag, const int value);


    /** Write one line, that starts and ends with similar tag to XML-file
     * A parameter between tags may be any string
     * \param tag A tag name without "<>"
     * \param value Same string
     * \sa writeMotionVector(), writeLine(), writeHeader(), writeFooter()
     */
    void writeLine(const char* tag, const QString &value);


    /** Get a string with required indent
     * Number of indentation is given by function "setIndentSize()"
     * \return A string with required indentation
     */
    QString indent() const;


private:
    QFile outFile;
    QTextStream out;
    QString fileName;
    int nestingLevel;
    int indentSize;
};

#endif // FSXMLWRITER_H
